package com.cmccgz.udacs_landlord_webapp.jpush.presenter;

import com.cmccgz.udacs_landlord_webapp.bean.PushRequestBean;
import com.cmccgz.udacs_landlord_webapp.data.PushRequestListDataSource;
import com.cmccgz.udacs_landlord_webapp.data.PushRequestRepository;
import com.cmccgz.udacs_landlord_webapp.jpush.contract.AccreditListContract;

import java.util.List;

public class AccreditListPresenter implements AccreditListContract.Presenter {
    private final PushRequestListDataSource dataSource;
    private AccreditListContract.View view;

    public AccreditListPresenter(AccreditListContract.View view) {
        this.view = view;
        dataSource = new PushRequestRepository();
    }

    @Override
    public void getPushRequestList(String q_word, String o_cond, final int page) {
        dataSource.getRequestList(q_word, o_cond, page + "", new PushRequestListDataSource.PushRequestListLisenter() {
            @Override
            public void getReqListSuccess(List<PushRequestBean> datas) {
                if (page==1) {
                    view.refreshPushReqListSuccess(datas);
                }else{
                    view.loadPushReqListSuccess(datas);
                }
            }

            @Override
            public void getReqListError(String msg) {
                if (page==1) {
                    view.refreshError(msg);
                }else{
                    view.loadError(msg);
                }
            }
        });
    }
}
